class ParkingLot {
  constructor(){
    this.cars=this.createParkingLot()
  }
  createParkingLot(){
    let parkingLot=[]
    for (let index = 1; index <=10; index++) {
      parkingLot.push({
        id:index,
        car:null
      })
      
    }
    return parkingLot
  }
  parking(){
    let parkingId=0
    let unparking=this.cars.filter(e=>e.car===null)
    if(!unparking.length) {
      alert('车已停满')
      return parkingId
    }
     parkingId=unparking[0].id
     this.cars.forEach(item=>item.id===parkingId?item.car='已停车':null)
     return parkingId
  }
  pickUp(id){
    let carMessage=this.cars.filter(item=>item.id===id)[0]
    if(!carMessage.car)return alert('此处没车')
    carMessage.car=null
    return `${id}号车位已取车`
  }
}
module.exports = ParkingLot;